AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("cl_debug.lua")
AddCSLuaFile("sh_team.lua")
AddCSLuaFile("cl_drawcircle.lua")

include("nwvar/nwvars.lua")
include("shared.lua")
include("admin.lua")
include("armory/init.lua")
include("commander/init.lua")
include("class/init.lua")
include("scoreboard/init.lua")
include("sh_team.lua")
include("resource/init.lua")

function GM:PlayerInitialSpawn( ply )

	//Let's choose a team for the poor soul
	//TODO: Team chooser
	
	local Team1Players	= table.Count(  team.GetPlayers( 1 ) )
	local Team2Players	= table.Count( team.GetPlayers( 2 ) )

	if Team1Players > Team2Players then
		ply:SetTeam( 2 )
	else
		ply:SetTeam( 1 )
	end

end

function GM:StartNewGame()

	GetWorldEntity().GameStartTime = CurTime()
	
	hook.Call("StartGame", GAMEMODE )

end

hook.Add("PlayerInitialSpawn", "StartGame", function()
	
	local PlayerCount = table.Count( player.GetAll() )

	if PlayerCount == 2 || (GAMEMODE.DEBUG == true && PlayerCount == 1) then
		GAMEMODE:StartNewGame()
	end

end )

hook.Add("PlayerLoadout", "GiveCommander", function( ply )
	
	ply:Give("garc_builder")
	ply:Give("weapon_physgun")
	ply:Give("weapon_crowbar")
	
	ply:Give( "weapon_stunstick" )
	ply:Give( "weapon_pistol" )
	ply:Give( "weapon_smg1" )
	ply:Give( "weapon_frag" )
	ply:Give( "weapon_physcannon" )

end )

hook.Add("ShowSpare2", "SendSpare1", function( ply )
	umsg.Start("Arc", ply)
    umsg.Char( 2 )
    umsg.End()
end )

hook.Add("ShowSpare1", "SendSpare2", function( ply )
	umsg.Start("Arc", ply)
    umsg.Char( 3 )
    umsg.End()
end )

hook.Add("StartGame", "SendClientGameStart", function()
	umsg.Start("Arc", ply)
    umsg.Char( 4 )
    umsg.End()
end )
